﻿// Decompiled with JetBrains decompiler
// Type: 我的小工具.SlnHelper
// Assembly: 开发辅助工具, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null
// MVID: F78E5980-5E94-4E46-ABDF-DC8C6CBF52AA
// Assembly location: K:\Tools\工具\开发辅助工具庆六一版\开发辅助工具2015-06-01\开发辅助工具.exe

using System;
using System.IO;
using System.Text;

namespace 我的小工具
{
  internal class SlnHelper
  {
    public string GetTFSAdrress(string strFilePath)
    {
      try
      {
        if (!File.Exists(strFilePath))
          return (string) null;
        using (StreamReader streamReader = File.OpenText(strFilePath))
        {
          string str;
          while ((str = streamReader.ReadLine()) != null)
          {
            if (str.Contains("SccTeamFoundationServer") && str.Contains("="))
            {
              streamReader.Close();
              return str.Split('=')[1].Trim();
            }
          }
          streamReader.Close();
        }
        return "";
      }
      catch (Exception ex)
      {
        return (string) null;
      }
    }

    public string GetVSSAdrress(string strFilePath)
    {
      try
      {
        if (!File.Exists(strFilePath))
          return (string) null;
        using (StreamReader streamReader = new StreamReader(strFilePath, Encoding.Default))
        {
          string str;
          while ((str = streamReader.ReadLine()) != null)
          {
            if (str.Contains("SCC_Aux_Path") && str.Contains("="))
            {
              streamReader.Close();
              return str.Split('=')[1].Trim(' ', '"');
            }
          }
          streamReader.Close();
        }
        return "";
      }
      catch (Exception ex)
      {
        return (string) null;
      }
    }

    public string GetSlnFilePath(string strHomePath)
    {
      if (Directory.Exists(strHomePath))
      {
        string path = strHomePath + "\\明源整体解决方案.sln";
        if (File.Exists(path))
          return path;
        FileInfo[] files = new DirectoryInfo(strHomePath).GetFiles("*.sln");
        if (files.Length > 0)
          return strHomePath + "\\" + files[0].ToString();
      }
      return "";
    }

    public string GetFormatVersion(string strFilePath)
    {
      try
      {
        if (!File.Exists(strFilePath))
          return (string) null;
        using (StreamReader streamReader = new StreamReader(strFilePath, Encoding.Default))
        {
          string str;
          while ((str = streamReader.ReadLine()) != null)
          {
            if (str.Contains("Microsoft Visual Studio Solution File, Format Version"))
            {
              streamReader.Close();
              return str.Substring(54).Trim();
            }
          }
          streamReader.Close();
        }
        return "";
      }
      catch (Exception ex)
      {
        return (string) null;
      }
    }
  }
}
